﻿using GN.Pay.TradeChannel.DefaultImpl;
using GN.Pay.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace GN.Pay.TradeChannel.Gyb.Request
{
    /// <summary>
    /// Web支付请求
    /// </summary>
    [Serializable]
    class WebPayRequest : APayRequest
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="order"></param>
        /// <param name="config"></param>
        public WebPayRequest(ITradeChannel channel,
           IOrderPayApply order,
           GybConfigure config) : base(channel, order,config)
        {
            this.MercUrl = HttpUtility.UrlEncode(config.PayNotifyUrl, Encoding.UTF8);
        }

        /// <summary>
        /// 
        /// </summary>
        public override string TranAbbr
        {
            get
            {
                return TradeCommand.IPER;
            }
        }

        /// <summary>
        /// 支付交易中，接收交易结果的url，如： http://aaa.bbb.ccc/receive.asp
        /// </summary>
        public string MercUrl { get; set; }     

        /// <summary>
        /// 卡密支付支付卡类型,非必输。0：借记卡和信用卡；空值或1：借记卡；3：信用卡；
        /// </summary>
        public string PayCardType { get; set; }

        /// <summary>
        /// 签约的信用卡账户,信用卡支付时需要，其他卡支付时不需要
        /// </summary>
        public string SignAcNo { get; set; }

        /// <summary>
        /// POS商户号
        /// </summary>
        public string PosMerId { get; set; }

        /// <summary>
        /// POS终端号,信用卡支付时需要，其他卡支付时不需要
        /// </summary>
        public string PosTermId { get; set; }

        /// <summary>
        /// POS商户MCC码,信用卡支付时需要，其他卡支付时不需要
        /// </summary>
        public string MccCode { get; set; }

        /// <summary>
        /// 请求渠道ID,移动终端送M，其它支付不需要
        /// </summary>
        public string ReqChannelId { get; set; }

        /// <summary>
        /// 生成
        /// </summary>
        /// <returns></returns>
        public override ITradePayApplyResult Build()
        {
            var plain = BuildPlain();
            SignDictionary dic = new SignDictionary();
            dic["transName"] = this.TranAbbr;
            dic["Plain"] = plain;
            dic["Signature"] = SecurityUtils.Sign(Config.ConfigureInfo, plain);
            var urlParams = dic.UrlLinkString();
            return new TradePayApplyResult("", Config.GatewayUrl, urlParams, TradePayApplyResultCallType.Web_Get);
        }
    }
}
